package main

import (
	"fmt"
	"strings"
)

func main () {
	fmt.Println(strings.Contains("seafood", "foo"))
	fmt.Println(strings.Contains("seafood", "bar"))
	fmt.Println(strings.Contains("seafood", ""))
	fmt.Println(strings.Contains("", ""))

	//对字符串切片进行连接
	s := []string{"foo", "bar", "baz"}
	fmt.Println(strings.Join(s, ","))

	s = []string{"a", "b", "c"}
	fmt.Println(strings.Join(s, "|"))

	//在字符串中查找sep所在位置,  找不到返回-1  从0开始计算
	fmt.Println(strings.Index("abc", "a1"))
	fmt.Println(strings.Index("abc", "bc"))

	//字符串重复count次并返回
	fmt.Println(strings.Repeat("a", 9))
	fmt.Println("ba" + strings.Repeat("na", 2))

	//字符串替换  string old new  count(替换次数) 小于0 全部替换
	fmt.Println(strings.Replace("hello", "l", "2", 0))

	//将字符串切割,返回切片
	fmt.Printf("%T\n", strings.Split("a,b,c", "0"))

	//头尾去除指定字符
	fmt.Printf("%s\n", strings.Trim("! abc !!", "! "))

	//按空格切割 并返回切片  包括换行符
	a := strings.Fields("a\rb\nc")
	for i,v := range a {
		fmt.Println(i, v)
	}
	fmt.Printf("%v", strings.Fields("a\rb\nc"))
}
